package com.stylefeng.guns.rest.modular.demo.lambda;

import com.stylefeng.guns.rest.modular.example.inter1;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.function.Consumer;
import java.util.function.IntPredicate;
import java.util.stream.IntStream;
@Slf4j
public class lambda {
    /***
     * lambda  表达式 取最大值 最小值  求和
     */
    @Test
public void  testLambda(){
    int[] nums={1,2,3,-10991,-9934,100};
    long start=System.currentTimeMillis();
    int min = IntStream.of(nums).parallel().min().getAsInt();
    long end=System.currentTimeMillis();
    log.info("花费时间:{}",end-start);
    int max = IntStream.of(nums).max().getAsInt();
    int sum = IntStream.of(nums).sum();
    log.info("min:{},max:{},sum:{}",min,max,sum);

}
@Test
public void test2(){
    inter1 i1=(i)->i*2;
     log.info("inter:{}",  i1.getNum(999,"100"));
}
@Test
public void test3(){
    IntPredicate predicate= i->i>0;
    log.info("测试:"+predicate.test(100));
    //消费函数接口(方法引用)
    Consumer<String> consumer= System.out::println;
    consumer.accept("输入的数据");

}
}
